import axios from 'axios'
import { closeLoading, openLoading, toast } from "./commion";
import store from '../store/index.js'

const httpRequest = axios.create({
    timeout: 60000,
    // baseURL: 'http://47.107.187.189:82'
    // baseURL: 'http://10.156.8.224'
    // baseURL: 'http://10.156.8.51'
    // baseURL: 'http://10.156.8.50'
})
//响应器
httpRequest.interceptors.request.use(
    config => {
        config.baseURL = store.getters.ip
        openLoading()
        return config
    },
    error => {
        toast(error.toString())
        return Promise.reject(error)
    }
)
//拦截器
httpRequest.interceptors.response.use(
    response => {
        closeLoading()
        if (response.data && response.data.status !== 200) {
            if (response.data.msg == '') {
                toast(response.data.msg)
            }
        }
        return response
    },
    error => {
        closeLoading()
        toast(error.toString());
        return error
    }
)

export default httpRequest
